require 'parser/SymFunction.rb'

class RangeFunction < SymFunction
    
    # Parameters are already checked, here we compare types
    def initialize
        @name = 'range'
        @type = 'vec'
        @param_types = ['num']
    end

    # Executes de function contained in 'self'
    # === Parameters
    # * params -> True value of the parameters that the function will be evaluated with
    # * func_table -> Symbol table of the declared functions
    # === Return value
    # nil if executed with success or an error message
    def execute params, func_table
      if params[0] < 1
        return "Tratando de crear vector de rango con número menor a 1 '#{params[0]}'"
      end
      v = []
      for i in (1..params[0])
        v.push(i)
      end
      @returned = Vector.new v
      @returned.type = 'vec_fil'
      nil
    end
end
